package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.common.DataTypeUtil;
import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.CE;
import com.sunwayhorizo.health.hl7.factories.ReferenceModifier;
import com.sunwayhorizo.health.hl7.persistent.RimCoreActCdSets;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQuery;

import org.jboss.seam.annotations.Name;

import static com.sunwayhorizo.health.hl7.vocabulary.ActCdSetCode.*;


@Name("PublicHealthCase")
@Entity
@NamedQuery(name = "PublicHealthCase.findAll", query = "select o from PublicHealthCase o")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("CASE")
public class PublicHealthCase extends Act implements Serializable {
    
/*    public CE detectionMethodCode;
    public CE diseaseImportedCode;
    public CE transmissionModeCode;
*/    
    public PublicHealthCase() throws Hl7Exception {
    }
    
    public PublicHealthCase(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }

    public void setDetectionMethodCode(CE ce) 
    {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            this.setRimCoreActCdSets(ce, PHDETECTIONMTHDCDSETCODE);
        }
        else
        {
            this.setPhDetectionMthdCodeEtsId(ce.code().toString());
        }
    }

    public CE getDetectionMethodCode() throws Hl7Exception 
    {
    	if (this.getPhDetectionMthdCodeEtsId().equals(PHDETECTIONMTHDCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getPhDetectionMthdCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getPhDetectionMthdCodeEtsId()); 
    	return null;  
    }

    public void setDiseaseImportedCode(CE ce) 
    {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            this.setRimCoreActCdSets(ce, PHDISEASEIMPTCDSETCODE);
        }
        else
        {
            this.setPhDiseaseImptCodeEtsId(ce.code().toString());
        }
    }

    public CE getDiseaseImportedCode() throws Hl7Exception 
    {
    	if (this.getPhDiseaseImptCodeEtsId().equals(PHDISEASEIMPTCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getPhDiseaseImptCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getPhDiseaseImptCodeEtsId()); 
    	return null;  
    }

    public void setTransmissionModeCode(CE ce) 
    {
    	if(null != ce && ce.codeSystemEnName()!=null && ce.codeName()!= null)
        {
            this.setRimCoreActCdSets(ce, PHTRANSMISSIONCDSETCODE);
        }
        else
        {
            this.setPhTransmissionCodeEtsId(ce.code().toString());
        }
    }

    public CE getTransmissionModeCode() throws Hl7Exception {
    	if (this.getPhTransmissionCodeEtsId().equals(PHTRANSMISSIONCDSETCODE.toString()))
        {
            for (RimCoreActCdSets actCdSets : this.getActCdSetsList())
            {
                if (this.getPhTransmissionCodeEtsId().equals(actCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(actCdSets); 
                }
            }            
        }
        else
            return DataTypeUtil.getCE(this.getPhTransmissionCodeEtsId()); 
    	return null;  
    }
    
    //Public Health Case    
        @Column(name = "PH_DETECTION_MTHD_CODE_ETS_ID")    
        private String phDetectionMthdCodeEtsId = PHDETECTIONMTHDCDSETCODE.toString();
        @Column(name = "PH_DISEASE_IMPT_CODE_ETS_ID")    
        private String phDiseaseImptCodeEtsId = PHDISEASEIMPTCDSETCODE.toString();
        @Column(name = "PH_TRANSMISSION_CODE_ETS_ID")    
    private String phTransmissionCodeEtsId = PHTRANSMISSIONCDSETCODE.toString();
        
    private String getPhDetectionMthdCodeEtsId() {
        return phDetectionMthdCodeEtsId;
    }

    private void setPhDetectionMthdCodeEtsId(String phDetectionMthdCodeEtsId) {
        this.phDetectionMthdCodeEtsId = phDetectionMthdCodeEtsId;
    }

    private String getPhDiseaseImptCodeEtsId() {
        return phDiseaseImptCodeEtsId;
    }

    private void setPhDiseaseImptCodeEtsId(String phDiseaseImptCodeEtsId) {
        this.phDiseaseImptCodeEtsId = phDiseaseImptCodeEtsId;
    }

    private String getPhTransmissionCodeEtsId() {
        return phTransmissionCodeEtsId;
    }

    private void setPhTransmissionCodeEtsId(String phTransmissionCodeEtsId) {
        this.phTransmissionCodeEtsId = phTransmissionCodeEtsId;
    }

}
